package com.itheima.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.itheima.dto.UserDto;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author CSY
 * 2022/5/18    16:11
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;


    /**
     * 查询是否为新用户
     *
     * @param phone
     * @return
     */
    @Override
    public UserDto getUser(String phone) {
        UserDto userDto = userMapper.selectByPhone(phone);
        return userDto;
    }

    @Override
    public boolean addUser(UserDto userDto) {
        String s = new Snowflake().nextIdStr();

        userDto.setId(s);
        userDto.setCreateTime(LocalDateTime.now());

        int i = userMapper.addUser(userDto);

        return i>0;
    }
}
